//WordCountStreaming1.scala
import org.apache.spark._
import org.apache.spark.streaming._
import org.apache.spark.SparkContext._
object WordCountStreaming1 {
  def main(args: Array[String]) {
    val sparkConf = new SparkConf().setAppName("WordCountStreaming1").setMaster("local[2]")
    //设置为本地运行模式，两个线程，一个监听，另一个处理数据
    val sc = new SparkContext(sparkConf)
    sc.setLogLevel("ERROR")
    val ssc = new StreamingContext(sc, Seconds(10))   // 时间间隔为10秒
    val lines = ssc.textFileStream("file:///home/hadoop/data")          
    //这里采用本地文件，当然也可以采用HDFS文件
    val words = lines.flatMap(_.split(" "))
    val wordCounts = words.count()
    wordCounts.print()
    ssc.start()
    ssc.awaitTermination()
  }
}
